import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JTabbedPane;
import java.awt.Font;
import java.math.*;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;

public class WPAbrutin extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField txtN;
    public JComboBox<String> comboBox;
    public JComboBox <String> comboBox_1;
    public JTextArea txtrInfod;
    public JTextArea txtrInfowpa;
    private JTextField txtPassLength;
    private JTextField txtKeysecond;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WPAbrutin frame = new WPAbrutin();
					frame.setDefaultLookAndFeelDecorated(true);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WPAbrutin() {
		super("WPA bruteforce Kalkulator by derryper");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setDefaultLookAndFeelDecorated(true);
		setBounds(100, 100, 558, 301);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(267, 31, 280, 199);
		contentPane.add(tabbedPane);
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("Process time", null, panel_2, null);
		panel_2.setLayout(null);
		
		comboBox_1 = new JComboBox();
		comboBox_1.setBounds(27, 11, 139, 20);
		comboBox_1.addItem("Alphanumericl");
		comboBox_1.addItem("Alphanumericlhex");
		comboBox_1.addItem("AlphanumericU");
		comboBox_1.addItem("AlphanumericUhex");
		comboBox_1.addItem("Custom");
		
		
		comboBox_1.addActionListener( new ActionListener(){
				public void actionPerformed(ActionEvent ev){
					int s = comboBox_1.getSelectedIndex();
					if (s==0){textField_1.setText("abcdefghijklmnopqrstuvwxyz1234567890");}
					if (s==1){textField_1.setText("abcdef1234567890");}
					if (s==2){textField_1.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");}
					if (s==3){textField_1.setText("ABCDEF1234567890");}
					if (s==4){textField_1.setText("");}
				}
		});
		panel_2.add(comboBox_1);
		
		textField_1 = new JTextField();
		textField_1.setBounds(27, 42, 139, 20);
		panel_2.add(textField_1);
		textField_1.setColumns(10);
		
		txtrInfod = new JTextArea();
		txtrInfod.setBounds(27, 104, 238, 67);
		panel_2.add(txtrInfod);
		
		JButton btnGenerar_1 = new JButton("Generar");
		btnGenerar_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {//Boton inicia action diccionarios time keys
					Generartim();
				
			}
		});
		btnGenerar_1.setBounds(176, 41, 89, 23);
		panel_2.add(btnGenerar_1);
		
		txtPassLength = new JTextField();
		txtPassLength.setText("  Pass length");
		txtPassLength.setBounds(176, 11, 86, 20);
		panel_2.add(txtPassLength);
		txtPassLength.setColumns(10);
		
		txtKeysecond = new JTextField();
		txtKeysecond.setText("      keys/second");
		txtKeysecond.setBounds(27, 73, 128, 20);
		panel_2.add(txtKeysecond);
		txtKeysecond.setColumns(10);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("Peso/Len", null, panel, null);
		panel.setLayout(null);
		
		 comboBox = new JComboBox();
		comboBox.setBounds(27, 5, 185, 20);
		comboBox.addItem("Alphanumericl");
		comboBox.addItem("Alphanumericlhex");
		comboBox.addItem("AlphanumericU");
		comboBox.addItem("AlphanumericUhex");
		comboBox.addItem("Custom");
		
		
		comboBox.addActionListener( new ActionListener(){
				public void actionPerformed(ActionEvent ev){
					int s =comboBox.getSelectedIndex();
					if (s==0){textField.setText("abcdefghijklmnopqrstuvwxyz1234567890");}
					if (s==1){textField.setText("abcdef1234567890");}
					if (s==2){textField.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");}
					if (s==3){textField.setText("ABCDEF1234567890");}
					if (s==4){textField.setText("");}
				}
		});
		panel.add(comboBox);
	//	String tmptxt = textField.getText();
		textField = new JTextField();
		textField.setBounds(27, 36, 182, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		txtrInfowpa = new JTextArea();
		txtrInfowpa.setBounds(27, 95, 183, 45);
		panel.add(txtrInfowpa); //new JScrollPane()
		
		JButton btnGenerar = new JButton("Generar");
		btnGenerar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//aqui dixionarios
				Generardlen();
			}
		});
		btnGenerar.setBounds(186, 67, 89, 23);
		panel.add(btnGenerar);
		
		txtN = new JTextField();
		txtN.setText("N#");
		txtN.setBounds(219, 36, 35, 20);
		panel.add(txtN);
		txtN.setColumns(10);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(118, 95, 35, 45);
		panel.add(scrollPane);
		
		JTextArea txtrbienvenido = new JTextArea();
		txtrbienvenido.setEditable(false);
		txtrbienvenido.setFont(new Font("Arial", Font.PLAIN, 10));
		txtrbienvenido.setText("                              ==BIENVENIDO==\r\nPara saber el tiempo necesario para completar\r\n un ataque de fuerza bruta\r\nindique los datos en el panel de al lado \r\ny saldr\u00E1 el tiempo necesario al\r\ndar al bot\u00F3n Generar Para saber la longitud/peso de un\r\n diccionario presione la solapa segunda y\r\nhaga lo mismo que en las instrucciones antes \r\nmencionadas\r\nPuede donar por paypal para ayudarme a \r\ncomprar librer\u00EDas y plugins para programar \r\na  av377@hotmail.com");
		txtrbienvenido.setBounds(0, 31, 261, 175);
		contentPane.add(txtrbienvenido);
	}
	    public void Generardlen(){
	    	txtrInfowpa.setText("");
			String tmptxt = textField.getText();
			int k = tmptxt.length();
			int j = Integer.parseInt(txtN.getText());
			double rformula = Math.pow(k, j) * (j+1);
			System.out.println(k +" <==================== k is");
			System.out.println(j);
			System.out.println(Math.pow(k, j));
			System.out.println(rformula);
			long rfolng = (long) rformula;
			System.out.println(rfolng);
			String s = String.valueOf(rfolng);
			txtrInfowpa.append( s+ " bytes \n"); 
			txtrInfowpa.append(String.valueOf(rfolng/1048576) + " Mb ");
			txtrInfowpa.append(String.valueOf(rfolng/1073741824) + " Gb +");
	    	
	    }
	    
	    public void Generartim(){
	    	txtrInfod.setText("");
	    	long numCombinations = 0;
	    	int passwordLength= Integer.parseInt(txtPassLength.getText());
	    	for (int x=1;x<=passwordLength;x++) {
	numCombinations = numCombinations + (long)Math.pow(textField_1.getText().length(),x);
} 
	    	int keysPerSecond = Integer.parseInt(txtKeysecond.getText());
	    	long seconds = numCombinations/keysPerSecond;

	    	long sub_years = (long)Math.floor(seconds / 31556926);
	    	long sub_days = (long)Math.floor((seconds % 31556926) / 86400);
	    	long sub_hours =(long) Math.floor(((seconds % 31556926) % 86400) / 3600);
	    	long sub_mins =(long) Math.floor((((seconds % 31556926) % 86400) % 3600) / 60);
	    	long sub_secs =(long) Math.floor((((seconds % 31556926) % 86400) % 3600) % 60);
	    	Object total = 0;
	    	total = "years" + sub_years;
	    	total = total + (" days"+ sub_days);
	    	total = total +(" hours"+ sub_hours);
	    	total = total +(" mins"+ sub_mins);
	    	total = total +(" sexs"+ sub_secs);
	    	txtrInfod.append((String)total);
	    	if (keysPerSecond >=40000){txtrInfod.append("\nAwesome speed you have there xD ");}
}
}